<?php $this->pageHeader('Rediger brukergruppe') ?>

<p id="top_right_links">
    <a href="<?php echo $this->url(array('module' => 'admin' , 'controller' => 'privilege', 'action' => 'edit', 'group' => $this->groupId)) ?>" class="button"><img src="<?php echo $this->imageLink('images/icons/privilege.png'); ?>" />Rediger rettigheter</a>
    <a href="<?php echo $this->url(array('module' => 'admin' , 'controller' => 'group', 'action' => 'delete', 'id' => $this->groupId)) ?>" class="button negative"><img src="<?php echo $this->imageLink('images/icons/delete.png'); ?>" />Slett</a>
</p>

<?php
    if($this->editSuccess) {
        echo $this->flashMessage()->renderMessage('Oppdatering utført', RedCross_View_Helper_FlashMessage::SUCCESS);
    } else if($this->editSuccess === false) {
        echo $this->flashMessage()->renderMessage('Kunne ikke oppdatere gruppen', RedCross_View_Helper_FlashMessage::ERROR);
    }
    if($this->addedUser) {
        echo $this->flashMessage()->renderMessage('La en bruker til i gruppen', RedCross_View_Helper_FlashMessage::SUCCESS);
    } else if($this->addedUser === false) {
        echo $this->flashMessage()->renderMessage('Kunne ikke legge brukeren til i gruppen', RedCross_View_Helper_FlashMessage::ERROR);
    }
    
    echo $this->flashMessage()->renderMessages();
?>

<h1>Rediger brukergruppe</h1>

<?php echo $this->editForm; ?>

<h5>Brukere</h5>
<?php if (count($this->group->Users) !== 0) : ?>
<table>
    <tr>
        <th>Navn</th>
        <th>Brukernavn</th>
        <th>&nbsp;</th>
    </tr>
<?php foreach ($this->group->Users as $user) : ?>
    <tr>
        <td>
            <a href="<?php echo $this->url(array('module' => 'core', 'controller' => 'user', 'action' => 'view', 'id' => $user['id'])); ?>">
                <?php echo $this->escape($user['Member']['first_name'] . ' ' . $user['Member']['last_name']); ?>
            </a> 
         </td>
        <td> <?php echo $this->escape($user['username']); ?></td>
        <td>
            <a href="<?php echo $this->url(array('action' => 'remove-user', 'id' => $this->group['id'], 'user' => $user['id'])); ?>">Fjern</a>
        </td>
    </tr>
<?php endforeach; ?>
</table>
<?php else : ?>
Denne gruppen har ingen medlemmer.
<?php endif; ?>

<p>&nbsp;</p>

<h5>Legg til ny bruker</h5>
<?php echo $this->addMemberForm; ?>
